<?php
if( !defined('IN_INDEX') )
{
	die('This page is hidden.');
}
if(!checkSession())
{
	function redirect($url)
			{
			?>
				<script type="text/javascript">
					{
					window.location = "<?php echo $url; ?>";
					}
				</script>
			<?php 
			}
			redirect("index.php?action=login");
	exit;
}
else
{
	if(isset($_REQUEST['id']))
	{
		$USER_PROFILE = new User('id', $_REQUEST['id']);
		$page_url = "index.php?action=profile&id=" . $_REQUEST['id'] . "&sub=stats";
	}
	else
	{
		$USER_PROFILE = $USER;
		$page_url = "index.php?action=profile&sub=stats";
	}
}
include('inc/functions_blog.php');
//include('Charts/Includes/FusionCharts.php');
$blogs = getTrainingList(" WHERE user_id='" . $USER_PROFILE->getId() . "'");
$dateformat = $CONFIG['date_format'];
?>

<link rel="stylesheet" href="./jscript/prettyphoto/css/prettyPhoto.css" type="text/css" media="screen" charset="utf-8" />
<script src="./jscript/prettyphoto/js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script>

<script type="text/javascript" src="./Highcharts/js/highcharts.js"></script>
<!--
	<SCRIPT LANGUAGE="Javascript" SRC="Charts/FusionCharts.js"></SCRIPT>
	<script src="./jscript/prettyphoto/js/jquery-1.4.4.min.js" type="text/javascript" charset="utf-8"></script>
-->

<div id='postpath'>
		<a title="<?php echo translate('gotofrontpage'); ?>" href="index.php"><?php echo translate('home'); ?></a>
		 &gt; <a href="index.php?action=blogs" title='<?php echo translate('showallblogs'); ?>'><?php echo translate('blog'); ?></a> 
         &gt; <a href="index.php?action=profile&id=<?php echo $USER_PROFILE->getId(); ?>"><?php echo ucf($USER_PROFILE->getFirstname()) . " " . ucf($USER_PROFILE->getLastname()); ?></a>
		&gt; <a href="index.php?action=profile&sub=stats&id=<?php echo $USER_PROFILE->getId(); ?>" title='<?php echo translate('stats'); ?>'><?php echo translate('stats'); ?></a>
        &gt; <a href="index.php?action=profile&sub=stats_progress&id=<?php echo $USER_PROFILE->getId(); ?>" title='<?php echo translate('myprogress'); ?>'><?php echo translate('myprogress'); ?></a>
</div>
<?php 

if(count($blogs) > 0)
{

?>
<br />
<h2><?php echo translate('myprogress'); ?></h2>
<br />
<?php echo translate('myprogress_text'); ?>
<br /><br />
<form method="POST" action="index.php?action=profile&sub=stats_progress&id=<?php echo $USER_PROFILE->getId(); ?>"> 

	<table border="0">
    <tr>
    
    <td>
	<b><?php echo ucf(translate('exercise')); ?>:</b>
    </td>
    
    <td>
	<select name="select_exercise">
   <?php
	$sql= mysql_query("SELECT lifts.exercise_id, lifts.training_id, training.training_id, training.user_id, exercise_name.ex_id, exercise_name.ex_name FROM lifts, training, exercise_name WHERE lifts.training_id=training.training_id AND exercise_name.ex_id=lifts.exercise_id AND training.user_id=".$USER_PROFILE->getId()." GROUP BY lifts.exercise_id ORDER BY ex_name");
	while($row = mysql_fetch_assoc($sql))
	{	
		$ex_id = $row['exercise_id'];
		$ex_name = getExercisename($row['exercise_id']);	
        echo '<option name="ex_id" value='. $ex_id.'';
		if(isset($_POST['select']) && $_POST['select_exercise']== $ex_id) { echo " selected='selected'"; }
		echo '>'. translate($ex_name) . '</option>';
    }
    ?>
	</select>
    </td>
        <td align="right">
        <b><?php echo ucf(translate('reps')); ?>:</b>
        </td>
        
        <td>
        <select name="reps">
        <option name="reps" value="1" <?php if(isset($_POST['select']) && $_POST['reps']== 1) { echo " selected='selected'"; } ?>>1RM</option>
        <option name="reps" value="2" <?php if(isset($_POST['select']) && $_POST['reps']== 2) { echo " selected='selected'"; } ?>>2RM</option>
        <option name="reps" value="3" <?php if(isset($_POST['select']) && $_POST['reps']== 3) { echo " selected='selected'"; } ?>>3RM</option>
        <option name="reps" value="4" <?php if(isset($_POST['select']) && $_POST['reps']== 4) { echo " selected='selected'"; } ?>>4RM</option>
        <option name="reps" value="5" <?php if(isset($_POST['select']) && $_POST['reps']== 5) { echo " selected='selected'"; } ?>>5RM</option>
        <option name="reps" value="6" <?php if(isset($_POST['select']) && $_POST['reps']== 6) { echo " selected='selected'"; } ?>>6RM</option>
        <option name="reps" value="7" <?php if(isset($_POST['select']) && $_POST['reps']== 7) { echo " selected='selected'"; } ?>>7RM</option>
        <option name="reps" value="8" <?php if(isset($_POST['select']) && $_POST['reps']== 8) { echo " selected='selected'"; } ?>>8RM</option>
        <option name="reps" value="9" <?php if(isset($_POST['select']) && $_POST['reps']== 9) { echo " selected='selected'"; } ?>>9RM</option>
        <option name="reps" value="10" <?php if(isset($_POST['select']) && $_POST['reps']== 10) { echo " selected='selected'"; } ?>>10RM</option>
        <option name="reps" value="11" <?php if(isset($_POST['select']) && $_POST['reps']== 11) { echo " selected='selected'"; } ?>>11RM</option>
        <option name="reps" value="12" <?php if(isset($_POST['select']) && $_POST['reps']== 12) { echo " selected='selected'"; } ?>>12RM</option>
        <option name="reps" value="13" <?php if(isset($_POST['select']) && $_POST['reps']== 13) { echo " selected='selected'"; } ?>>13RM</option>
        <option name="reps" value="14" <?php if(isset($_POST['select']) && $_POST['reps']== 14) { echo " selected='selected'"; } ?>>14RM</option>
        <option name="reps" value="15" <?php if(isset($_POST['select']) && $_POST['reps']== 15) { echo " selected='selected'"; } ?>>15RM</option>
        <option name="reps" value="16" <?php if(isset($_POST['select']) && $_POST['reps']== 16) { echo " selected='selected'"; } ?>>16RM</option>
        <option name="reps" value="17" <?php if(isset($_POST['select']) && $_POST['reps']== 17) { echo " selected='selected'"; } ?>>17RM</option>
        <option name="reps" value="18" <?php if(isset($_POST['select']) && $_POST['reps']== 18) { echo " selected='selected'"; } ?>>18RM</option>
        <option name="reps" value="19" <?php if(isset($_POST['select']) && $_POST['reps']== 19) { echo " selected='selected'"; } ?>>19RM</option>
        <option name="reps" value="20" <?php if(isset($_POST['select']) && $_POST['reps']== 20) { echo " selected='selected'"; } ?>>20RM</option>
        <option name="reps" value="0" <?php if(isset($_POST['select']) && $_POST['reps']== 0) { echo " selected='selected'"; } ?>><?php echo ucf(translate('max')); ?></option>
        </select>
        </td>
        
        <td>
        <b><?php echo ucf(translate('meet')); ?>:</b>
        </td>
        
        <td>
        <select name="meet">
		<option name="meet" value="0" <?php if(isset($_POST['select']) && $_POST['meet']== 0) { echo " selected='selected'"; } ?>>Nei</option>
		<option name="meet" value="1" <?php if(isset($_POST['select']) && $_POST['meet']== 1) { echo " selected='selected'"; } ?>>Ja</option>
        <option name="meet" value="2" <?php if(isset($_POST['select']) && $_POST['meet']== 2) { echo " selected='selected'"; } ?>>Ja og nei</option>
		</select>
        </td>
    
        <td>
        <input type="hidden" name="user_id" value="<?php echo $USER_PROFILE->getId(); ?>"  />
        <input type="submit" style="font-weight:bold;" name="select" value=" <?php echo ucf(translate('show')); ?> "  />
        </td>
    </table>
</form>

<?php 
if(isset($_POST['select']))
{
	$ex_id = $_POST['select_exercise'];
	$nr_reps = $_POST['reps'];
	$user_id = $_POST['user_id'];
	$meet = $_POST['meet'];

if($meet == 0)
{
	echo "<br /><h1>" . ucf(translate(getExercisename($ex_id))) . " - "; 
	if($nr_reps == 0)
	{
	 echo ucf(translate('max')) . "</h1><br />";
	}
	else
	{
	 echo $nr_reps . "RM</h1><br />";
	}
}
elseif($meet == 1)
{
	echo "<br /><h1>" . ucf(translate(getExercisename($ex_id))) . " - "; 
	if($nr_reps >= 0)
	{
	 echo ucf(translate('meet')) . "</h1><br />";
	}
}
elseif($meet == 2)
{
	echo "<br /><h1>" . ucf(translate(getExercisename($ex_id))) . " - "; 
	if($nr_reps == 0)
	{
	 echo ucf(translate('max')) . "</h1><br />";
	}
	else
	{
	 echo $nr_reps . "RM - " . translate('trainingandmeet') ."</h1><br />";
	}
}

if($nr_reps == 0)
{
	//Training only
	if($meet == 0)
	{
	// Get all the data
	$result = mysql_query("SELECT DISTINCT
	training.date, 
	max(lifts.kg) as kg,
	lifts.rep,
	lifts.url,
	training.training_id,
	training.place,
	training.meet,
	training.bodyweight
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND training.meet = 0 AND lifts.kg > 0 AND lifts.rep > 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ."
	GROUP BY training_id ORDER BY training.date") or die(mysql_error());
	
	// Get the PB
	$result_pb = mysql_query("SELECT DISTINCT
	lifts.kg,
	training.training_id,
	training.date
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND training.meet = 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ." ORDER BY -kg, training.date LIMIT 1") or die(mysql_error());
	
	// Get the last/badest lift
	$result_bpb = mysql_query("SELECT DISTINCT 
	max(lifts.kg) as kg,
	training.training_id,
	training.date
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND training.meet = 0 AND lifts.kg > 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ." GROUP BY training_id ORDER BY training.date LIMIT 1") or die(mysql_error());
	}
	
	//Meet only
	elseif($meet == 1)
	{
	// Get all the data
	$result = mysql_query("SELECT DISTINCT
	training.date, 
	max(lifts.kg) as kg,
	lifts.rep,
	lifts.url,
	training.training_id,
	training.place,
	training.meet,
	training.bodyweight
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND training.meet = 1 AND lifts.kg > 0 AND lifts.rep > 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ."
	GROUP BY training_id ORDER BY training.date") or die(mysql_error());
	
	// Get the PB
	$result_pb = mysql_query("SELECT DISTINCT
	lifts.kg,
	training.training_id,
	training.date
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND training.meet = 1 AND lifts.kg > 0 AND lifts.rep > 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ." ORDER BY -kg, training.date LIMIT 1") or die(mysql_error());
	
	// Get the last/badest lift
	$result_bpb = mysql_query("SELECT DISTINCT 
	max(lifts.kg) as kg,
	training.training_id,
	training.date
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND training.meet = 1 AND lifts.kg > 0 AND lifts.rep > 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ." GROUP BY training_id ORDER BY training.date LIMIT 1") or die(mysql_error());
	}
	
	//Both meet and training
	elseif($meet == 2)
	{
	// Get all the data
	$result = mysql_query("SELECT DISTINCT
	training.date, 
	max(lifts.kg) as kg,
	lifts.url,
	lifts.rep,
	training.training_id,
	training.place,
	training.bodyweight
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND lifts.kg > 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ."
	GROUP BY training_id ORDER BY training.date") or die(mysql_error());
	
	// Get the PB
	$result_pb = mysql_query("SELECT DISTINCT
	lifts.kg,
	training.training_id,
	training.date
	FROM lifts, training
	WHERE training.training_id=lifts.training_id and exercise_id= ". $ex_id ." AND training.user_id =". $user_id ." ORDER BY -kg, training.date LIMIT 1") or die(mysql_error());
	
	// Get the last/badest lift
	$result_bpb = mysql_query("SELECT DISTINCT 
	max(lifts.kg) as kg,
	training.training_id,
	training.date
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND lifts.kg > 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ." GROUP BY training_id ORDER BY training.date LIMIT 1") or die(mysql_error());	
	}
}
else
{
	//Training only
	if($meet == 0)
	{
	// Get all the data
	$result = mysql_query("SELECT DISTINCT
	training.date, 
	max(lifts.kg) as kg,
	lifts.url,
	training.training_id,
	training.place,
	training.meet,
	training.bodyweight
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND training.meet = 0 AND lifts.rep = ". $nr_reps ." AND lifts.kg > 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ."
	GROUP BY training_id ORDER BY training.date") or die(mysql_error());
	
	// Get the PB
	$result_pb = mysql_query("SELECT DISTINCT
	lifts.kg,
	training.training_id,
	training.date
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND training.meet = 0 AND lifts.rep = ". $nr_reps ." and exercise_id= ". $ex_id ." AND training.user_id =". $user_id ." ORDER BY -kg, training.date LIMIT 1") or die(mysql_error());
	
	// Get the last/badest lift
	$result_bpb = mysql_query("SELECT DISTINCT 
	max(lifts.kg) as kg,
	training.training_id,
	training.date
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND training.meet = 0 AND lifts.rep = ". $nr_reps ." AND lifts.kg > 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ." GROUP BY training_id ORDER BY training.date LIMIT 1") or die(mysql_error());
	}
	
	//Meet only
	elseif($meet == 1)
	{
	// Get all the data
	$result = mysql_query("SELECT DISTINCT
	training.date, 
	max(lifts.kg) as kg,
	lifts.url,
	training.training_id,
	training.place,
	training.meet,
	training.bodyweight
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND training.meet = 1 AND lifts.rep = ". $nr_reps ." AND lifts.kg > 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ."
	GROUP BY training_id ORDER BY training.date") or die(mysql_error());
	
	// Get the PB
	$result_pb = mysql_query("SELECT DISTINCT
	lifts.kg,
	training.training_id,
	training.date
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND training.meet = 1 AND lifts.rep = ". $nr_reps ." and exercise_id= ". $ex_id ." AND training.user_id =". $user_id ." ORDER BY -kg, training.date LIMIT 1") or die(mysql_error());
	
	// Get the last/badest lift
	$result_bpb = mysql_query("SELECT DISTINCT 
	max(lifts.kg) as kg,
	training.training_id,
	training.date
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND training.meet = 1 AND lifts.rep = ". $nr_reps ." AND lifts.kg > 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ." GROUP BY training_id ORDER BY training.date LIMIT 1") or die(mysql_error());
	}
	
	//Both meet and training
	elseif($meet == 2)
	{
	// Get all the data
	$result = mysql_query("SELECT DISTINCT
	training.date, 
	max(lifts.kg) as kg,
	lifts.url,
	training.training_id,
	training.place,
	training.bodyweight
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND lifts.rep = ". $nr_reps ." AND lifts.kg > 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ."
	GROUP BY training_id ORDER BY training.date") or die(mysql_error());
	
	// Get the PB
	$result_pb = mysql_query("SELECT DISTINCT
	lifts.kg,
	training.training_id,
	training.date
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND lifts.rep = ". $nr_reps ." and exercise_id= ". $ex_id ." AND training.user_id =". $user_id ." ORDER BY -kg, training.date LIMIT 1") or die(mysql_error());
	
	// Get the last/badest lift
	$result_bpb = mysql_query("SELECT DISTINCT 
	max(lifts.kg) as kg,
	training.training_id,
	training.date
	FROM lifts, training
	WHERE training.training_id=lifts.training_id AND lifts.rep = ". $nr_reps ." AND lifts.kg > 0 AND exercise_id= ". $ex_id ." AND training.user_id =". $user_id ." GROUP BY training_id ORDER BY training.date LIMIT 1") or die(mysql_error());	
	}
}

$num = mysql_num_rows($result);
$i=1;
//	$strXML = "<chart caption='" . ucf(translate('myprogress')) . " - " . ucf(translate(getExercisename($ex_id))) . " ". $nr_reps . "RM" . "' subCaption='" . ucf(translate('for')) . " " . getNameFromId($USER_PROFILE->getId()) . "' showBorder='1' formatNumberScale='0' numberSuffix='". $w_metric ."' baseFont='Arial' exportEnabled='1' exportAtClient='0' exportHandler='Charts/ExportHandlers/PHP/FCExporter.php' exportAction='download' exportTargetWindow='_blank' exportFileName='" . ucf(translate('myprogress')) . "'>";

if($i <= $num)
{ 
		echo "<table><tr><td>
			<table border='1'>";
		echo "<tr><th>" . translate('date') . "</th><th>". ucf(translate('place')) ."</th><th>" . ucf(translate('bodyweight')) . "</th><th>". translate('lifted') ."</th></tr>";
		
		$max_kg = 0;
		
		$array_date = array();
		$array_weight = array();
		$array_url = array();
		
		// keeps getting the next row until there are no more to get
		while($row = mysql_fetch_array($result)) 
		{
			if(r_nr(calcFromKg($row['kg'])) > $max_kg)
			{
				$max_kg = r_nr(calcFromKg($row['kg']));
	
				// Print out the contents of each row into a table
				echo "<tr><td width='140' align='center'>";
				echo formatDate($row['date'], $dateformat);
				echo "</td><td width='160' align='center'>";
				echo $row['place'];
				echo "</td><td width='100' align='center'>";
				echo r_nr2(calcFromKg($row['bodyweight'])). $w_metric;
				echo "</td><td width='130' align='center'>"; 
				echo "<a style='color:#555555;' href='index.php?action=profile&sub=show&tid=". $row['training_id'] ."'>";
			
				$array_url[] = "index.php?action=profile&sub=show&tid=". $row['training_id'] ;
				$array_date[] = ($row['date']);
				if($w_metric == "kg")
				{
					echo "<b>" . r_nr2(calcFromKg($row['kg'])). $w_metric . "</b></a>"; 
					//if($nr_reps == 0 && $meet != 1) { echo " x " . $row['rep']; }
				
					// $strXML .= "<set label='" . formatDate($row['date'], $dateformat) . "' value='" . $row['kg'] . "' tooltext='" . r_nr2(calcFromKg($row['kg'])). $w_metric . "{br}". formatDate($row['date'], $dateformat) ."{br}". $row['place'] ."' />";
				
					if($row['url'] != "")
					{
						echo " <a href='" . $row['url'] . "' rel='prettyPhoto'><img alt='". translate('show_video') ."' src='img/video.png' /></a>";
					}
					$array_weight[] =  r_nr2(calcFromKg($row['kg']));
				}
				else
				{
					echo "<b>" . r_nr(calcFromKg($row['kg'])). $w_metric . "</b></a>";
					//if($nr_reps == 0 && $meet != 1) { echo " x " . $row['rep']; }
				
				 	//$strXML .= "<set label='" . formatDate($row['date'], $dateformat) . "' value='" . $row['kg'] . "' tooltext='" . r_nr(calcFromKg($row['kg'])). $w_metric . "{br}". formatDate($row['date'], $dateformat) ."{br}". $row['place'] ."'/>";
				
					if($row['url'] != "")
					{
						echo " <a href='" . $row['url'] . "' rel='prettyPhoto'><img alt='". translate('show_video') ."' src='img/video.png' /></a>";
					}
					$array_weight[] =  r_nr(calcFromKg($row['kg']));
				}
				echo "</td></tr>"; 
				$i++;
				$counter = $i;
			}
			
		}
		//$strXML .= "</chart>";
		
		$check = $counter-1;
		echo "</table></td>
			<td valign='top' style='padding-left: 50px;'>
						<table border='0'>
								<tr>
									<td>";
								if($check >= 2)
								{
									while($row2 = mysql_fetch_array($result_pb)) 
									{
									echo translate('mycurrentpris') .  ": <b>" . r_nr(calcFromKg($row2['kg'])). $w_metric . "</b> (" . formatDate($row2['date'], $dateformat) . ")";
									$curpr = r_nr(calcFromKg($row2['kg']));
									$curdate = $row2['date'];
									}
									echo "
									</td>
								</tr>";
								
								echo "<tr>
									<td>";
									while($row3 = mysql_fetch_array($result_bpb)) 
									{
									echo translate('myfirstprwas') .  ": <b>" . r_nr(calcFromKg($row3['kg'])). $w_metric . "</b> (" . formatDate($row3['date'], $dateformat) . ")";
									$oldpr = r_nr(calcFromKg($row3['kg']));
									$olddate = $row3['date'];
									}
									echo "
									</td>
								</tr>
								
								<tr>
									<td colspan='2'>";
									$diff = $curpr-$oldpr;
									$diff_pro = round((($curpr-$oldpr)/$oldpr*100), 2);
									echo "<b>" . $diff. $w_metric . "/" . $diff_pro . "%</b> " . translate('increase') . " " . strtolower(translate('in')) . " ca. " . getHowLongAgo2($olddate, $curdate) . ".";
									echo "
									</td>
								</tr>";
								}
						echo "</table>
			</td>
		</tr>
		</table><br />";		
		if($check >= 2) //graph start
		{
			//echo renderChart("Charts/Line.swf", "", $strXML, "".ucf(translate('myprogress'))."", 900, 400, false, true);
			
			//$array_date = array();
			//$array_weight = array();
			//$array_url = array();
			$array_segment = array();
			$date_json = array();
			$url_json = array();
			for($i= 0 ;$i < count($array_date) ; $i++){
				if($i == 0){
					$t = 1;
					$array_segment[] = $t;
				}else{
					$t = $array_segment[$i-1]+ ceil( ($array_date[$i]- $array_date[$i-1])/86400 );
					$array_segment[] = $t ;
				}
				$date_json[$t] =  formatDate($array_date[$i], $dateformat);
				$url_json[$t]  = "".$array_url[$i]."";
			}
			//print_r($array_segment);
			// [[20, 20], [80, 80], [84,90],[86,120]]
			$array_merge = array();
			for($i = 0 ;$i <count($array_segment); $i++){
				$array_merge[] = "[". $array_segment[$i]. ",". $array_weight[$i] ."]";
			}
			
			
			
			$data_list = "[".implode(",", $array_merge). "]";
			$json_js = json_encode($date_json);
			$json_url = json_encode($url_json);
		}
	?>
	
<div id="container_graph" style="width: auto; height: auto; margin: 0 auto"></div>

		<script type="text/javascript">
			var json = eval(<?php echo $json_js; ?>);
			var json_url = eval(<?php echo $json_url; ?>);
			var kg_title = '<?php echo translate("Kg");?>';
			
			var chart;
			$(document).ready(function() {
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container_graph',
						defaultSeriesType: 'scatter',
						margin: [70, 50, 60, 80],
					
					},  
					title: {
						text: '<?php echo ucf(translate("myprogress")) . " - " . ucf(translate(getExercisename($ex_id))) . " ". $nr_reps . "RM"  ;?>'
					},
					subtitle: {
						text: '<?php echo ucf(translate("for")) . " " . getNameFromId($USER_PROFILE->getId());?>'
					},
					xAxis: {
						minPadding: 0.2,
						maxPadding: 0.2,
						type: 'Value',
						labels: {
							formatter: function() {
								//return Highcharts.dateFormat('%a %d %b', this.value);
								//console.debug(this);
								return '';
							}
						}
					},
					yAxis: {
						title: {
							text: '<?php echo translate("weight_unit");?>',
						},
						minPadding: 0.2,
						maxPadding: 0.2,
						maxZoom: 60,
						plotLines: [{
							value: 0,
							width: 1,
							color: '#808080'
						}]
					},
					legend: {
						enabled: false
					},
					plotOptions: {
						series: {
							lineWidth: 1,
							dataLabels: {
								enabled: true,
								formatter: function() {
									return this.y+''+ kg_title +'<br />'+ json[this.x];
								},
								x: -40,
								y:0
							},
							cursor: 'pointer',
				            point: {
				                events: {
				                    click: function() {
				                        location.href = json_url[this.x];
				                    }
				                }
				            }
						}
					},
					tooltip: {
						formatter: function() {
							return this.y+''+ kg_title +'<br />'+ json[this.x] ;
						}
					},
					series: [{
						data: eval('<?php echo $data_list; ?>')
					}]
				});
				
				
			});
				
		</script>
		
	<?php	
		echo "<div class='fixed'>
							</div>
						</div>
						</div>
					<div class='fixed'>
					</div>
					<div id='footer'>
					<a id='gotop' href='#' onclick='MGJS.goTop();return false;'>" . translate('top') . "</a>
						<div align='center' id='copyright'>&copy; " . translate('copyrightyear') . " " . translate('header_text'). " - " .  translate('curversion') ." - <a href='index.php?action=contact'>" . translate('contact') ."</a> - <a href='index.php?action=about'>" . translate('about') . "</a> - " . translate('onlineusers'). ": " . getActiveUsers() . "<br />
						
						<br />
				
				<a rel='license' href='http://creativecommons.org/licenses/by-nc/3.0/'>
				<img alt='Creative Commons License' style='border-width:0' 
				src='http://i.creativecommons.org/l/by-nc/3.0/80x15.png' /></a>
				<br />This work is licensed under a <a rel='license' href='http://creativecommons.org/licenses/by-nc/3.0/'>
				Creative Commons Attribution-NonCommercial 3.0 Unported License</a>.	
					</div>	
						
						</div>";
						?>
                        <script type="text/javascript" charset="utf-8">
						  $(document).ready(function(){
							$("a[rel^='prettyPhoto']").prettyPhoto();
						  });
						</script>
                        <?php
			exit;
			
}
else
{
	echo translate('noresultshof');
	echo "<div class='fixed'>
					</div>
				</div>
				</div>
			<div class='fixed'>
			</div>
			<div id='footer'>
			<a id='gotop' href='#' onclick='MGJS.goTop();return false;'>" . translate('top') . "</a>
				<div align='center' id='copyright'>&copy; " . translate('copyrightyear') . " " . translate('header_text'). " - " .  translate('curversion') ." - <a href='index.php?action=contact'>" . translate('contact') ."</a> - <a href='index.php?action=about'>" . translate('about') . "</a> - " . translate('onlineusers'). ": " . getActiveUsers() . "<br />
                </div>";
				?>
                        <script type="text/javascript" charset="utf-8">
						  $(document).ready(function(){
							$("a[rel^='prettyPhoto']").prettyPhoto();
						  });
						</script>
                        <?php
	exit;
} 
}
}
else
{
  echo "<br /><br /><br /><br /><br /><br /><br /><br /><br />
		<center><h2>" . translate('addanewtrainingtostart') . "</h2></center>";
}
?>